﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace VueShopApi.Common.Extension
{
    public static class ModelStateExtensions
    {
        public static string GetFirstOrDefaultError(this ModelStateDictionary modelState)
        {
            //找到出错的字段以及出错信息
            return modelState.Where(m => m.Value.Errors.Any()).Select(x => $"{x.Key}:{x.Value.Errors.Select(e => e.ErrorMessage).FirstOrDefault()}").FirstOrDefault();
        }
    }
}
